#define _CRT_SECURE_NO_WARNINGS


#include <stdio.h>

void PrintArrar(int* a, int n)
{
	for (int i = 0; i < n; ++i)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}

void ShellSort(int* a, int n)
{
	int gap = n;
	while (gap > 1)
	{
		gap = gap / 2;

		for (int i = 0; i < n - gap; ++i)
		{
			int end = i;
			int tmp = a[end + gap];

			while (end >= 0)
			{
				if (a[end] > tmp)
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}
	
}

void TestShellSort()
{
	int arr[] = { 9,8,7,6,5,4,3,2,1 };
	ShellSort(arr, sizeof(arr) / sizeof(int));
	PrintArrar(arr, sizeof(arr) / sizeof(int));
}

int main()
{
	TestShellSort();
	return 0;
}